home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 5.4 KB | 162 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWExcept.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- //========================================================================================
- // THEORY OF OPERATION
- //
- // This subsystem provides an emulation for C++ exception handling for compilers that
- // do not yet support exceptions.
- //
- // When an exception is thrown, the stack is unwound to the first enclosing try/catch
- // block. Automatic (stack) objects are destroyed during stack unwinding. Exceptions
- // thrown during the construction of either an automatic or a dynamic (heap) object will
- // result in the fully constructed subobjects of the partially constructed object
- // being destroyed.
- //
- // To obtain this behavior with exception handling emulation, the programmer must do
- // extra work. Classes which are to be destroyed during unwinding must be "registered"
- // as auto-destruct classes, and each constructor and destructor must invoke macros
- // so that the emulation subsystem can track which objects have been fully constructed
- // and when they go out of scope.
- //
- //========================================================================================
-
- #ifndef FWEXCEPT_H
- #define FWEXCEPT_H
-
- #ifndef FW_NATIVE_EXCEPTIONS
-
- #ifndef SLPRIMEM_H
- #include "SLPriMem.h"
- #endif
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- #ifndef FWCLAINF_H
- #include "FWClaInf.h"
- #endif
-
- #ifndef FWEXCIMP_H
- #include "FWExcImp.h"
- #endif
-
- #include <stddef.h>
- #include <setjmp.h>
-
- //========================================================================================
- // template <class T> FW_PrivStaticDestroyer(T*)
- //
- // A template function that invokes the class T's destructor, using a static dispatch.
- // Even if the destructor for class T is virtual, a non-virtual function dispatch will be used.
- //========================================================================================
-
- template <class T>
- inline void FW_PrivStaticDestroyer(T* self)
- {
- self->T::~T();
- }
-
- //========================================================================================
- // template <class T> FW_PrivClone(T*)
- //
- // A template function that invokes the class T's copy constructor to clone an
- // instance of class T into a raw destination buffer
- //========================================================================================
-
- template <class T>
- inline void FW_PrivClone(T* self, void* destination, size_t size)
- {
- #ifndef FW_DEBUG
- FW_UNUSED(size);
- #endif
- FW_PRIV_ASSERT(destination);
- FW_PRIV_ASSERT(size >= sizeof(T));
- new(destination) T(*self);
- }
-
- //========================================================================================
- // class FW_CPrivWatcher
- //========================================================================================
-
- class FW_CPrivWatcher : public FW_SPrivWatcher
- {
- public:
- FW_CPrivWatcher(FW_PrivDeleteProc deleter)
- { FW_PrivWatcher_Init(this, deleter); }
- ~FW_CPrivWatcher()
- { FW_PrivWatcher_Destroy(this); }
- };
-
- //========================================================================================
- // CLASS FW_CPrivTryBlockContext
- //========================================================================================
-
- class FW_CPrivTryBlockContext : public FW_SPrivTryBlockContext
- {
- public:
- FW_CPrivTryBlockContext(jmp_buf buffer, FW_PrivLongJumpProc jumpProc)
- { FW_PrivTryBlockContext_Init(this, buffer, jumpProc); }
-
- ~FW_CPrivTryBlockContext()
- { FW_PrivTryBlockContext_Destroy(this); }
- };
-
- //========================================================================================
- // template <class T> FW_PrivThrowException(const T& exception)
- //========================================================================================
-
- template <class T>
- inline void FW_PrivThrowException(const T& exception)
- {
- FW_PrivThrow((void*) &exception,
- sizeof(T),
- exception.PrivVirtualGetClassInfo(),
- FW_PrivGetDestroyProc(&exception),
- FW_PrivGetCloneProc(&exception));
- }
-
- //========================================================================================
- // template <class T> FW_PrivGetAutoName(T*)
- //
- // We declare this function as a template function even though it will "specialized" for every instantiation via
- // the FW_DEFINE_AUTO macros.
- //========================================================================================
-
- #ifdef FW_DEBUG
- template <class T>
- char* FW_PrivGetAutoName(const T*);
- #endif
-
- //========================================================================================
- // template <class T> FW_PrivGetDestroyProc(T*)
- //
- // We declare this function as a template function even though it will "specialized" for every instantiation via
- // the FW_DEFINE_AUTO macros.
- //========================================================================================
-
- template <class T>
- FW_PrivDestroyProc FW_PrivGetDestroyProc(const T*);
-
- //========================================================================================
- // template <class T> FW_PrivGetDeleteProc(T*)
- //
- // We declare this function as a template function even though it will "specialized" for every instantiation via
- // the FW_DEFINE_AUTO macros.
- //========================================================================================
-
- template <class T>
- FW_PrivDeleteProc FW_PrivGetDeleteProc(const T*);
-
- #endif
-
- #endif
-
-